import 'package:flutter/material.dart';

final networkImageReg = RegExp('^http');
final staticImageReg = RegExp('^static');

class CommonImage extends StatelessWidget {
  final String src;
  final double width;
  final double height;
  final BoxFit fit;

  const CommonImage(this.src,{Key key, this.width, this.height, this.fit}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    if(networkImageReg.hasMatch(src)){
      return Image.network(
        src,
        width: width,
        height: height,
        fit: fit,
      );
    }
    if(staticImageReg.hasMatch(src)){
      return Image.asset(
        src,
        width: width,
        height: height,
        fit: fit,
      );
    }
    assert(false,'图片地址不合法');
    return Container(child: Text("图片加载失败"),);
  }
}
